/************************************************/
/************************************************/
/**** PART 5: REPLICATE APPENDIX RESULTS  ****/
/************************************************/
/************************************************/




********************************************************************************
***Table A.1 Balance Tests
********************************************************************************

	foreach y in Admit ADI lnConsulttime {

		qui xi:reg `y' i.BrDx
		predict `y'hat

		qui xi:reg `y'hat SameRace i.doctorid $xlist_exante, vce(cluster doctorid)
		qui summ `y'hat if e(sample)
		outreg2 using TableA1, excel append label ctitle(`y') keep( SameRace) ///
		bdec(5) sdec(5) rdec(3) adec(3) addstat(Mean, r(mean)) nocons

	}


********************************************************************************
***Table A.2 Marginal Effects from Probit and Logit Regressions
********************************************************************************

	***Panel A. Probit

	foreach y in Admit ADI Revisit Death {

		qui xi:probit `y'  SameRace i.doctorid $xlist, vce(cluster doctorid)
		margins,dydx(SameRace) post
		qui summ `y' if e(sample)
		outreg2 using TableA2, excel append label ctitle(margins) keep( SameRace) ///
		 bdec(4) sdec(4) rdec(3) adec(3) addstat(Mean, r(mean)) nocons

	}


	***Panel B. Logit

	foreach y in Admit ADI Revisit Death {

		qui xi:logit `y'  SameRace i.doctorid $xlist, vce(cluster doctorid)
		margins,dydx(SameRace) post
		qui summ `y' if e(sample)
		outreg2 using TableA2, excel append label ctitle(margins) keep( SameRace) ///
		 bdec(4) sdec(4) rdec(3) adec(3) addstat(Mean, r(mean)) nocons

	}




********************************************************************************
***Table A.3 Alternative Measures of Medical Tests
********************************************************************************

	foreach y in ImageUse LabUse TestCount{

		qui xi:reg `y'  SameRace i.doctorid $xlist, vce(cluster doctorid)

		qui summ `y' if e(sample)

		outreg2 using TableA3, excel append label ctitle(`y') keep( SameRace) ///
		bdec(4) sdec(4) rdec(3) adec(3) addstat(Mean, r(mean)) nocons

	}



********************************************************************************
***Table A.4 Deterministic Race-Concordance Status
********************************************************************************
	preserve

	keep if Proportion_Samerace==0|Proportion_Samerace==1

	foreach y in Admit ADI lnConsulttime Revisit Death{

		qui xi:reg `y'  SameRace i.doctorid $xlist, vce(cluster doctorid)

		qui summ `y' if e(sample)

		outreg2 using TableA4, excel append label ctitle(`y') keep( SameRace) ///
		 bdec(4) sdec(4) rdec(3) adec(3) addstat(Mean, r(mean)) nocons

	}

	restore



********************************************************************************
***Table A.5 Robustness: Physician Fatigue and End of Shift Effects
********************************************************************************

	***Panel A
	foreach y in Admit ADI lnConsulttime Revisit Death{

		qui xi:reg `y' SameRace i.doctorid $xlist priorcase i.workhour, vce(cluster doctorid)
		
		qui summ `y' if e(sample)
		
		outreg2 using TableA5, excel append label ctitle(`y') keep(SameRace)  ///
		bdec(4) sdec(4) rdec(3) adec(3) addstat(Mean, r(mean)) nocons

	}

	***Panel B
	foreach y in Admit ADI lnConsulttime Revisit Death{

		qui xi:reg `y' SameRace i.doctorid $xlist i.irelto, vce(cluster doctorid)
		
		qui summ `y' if e(sample)
		
		outreg2 using TableA5, excel append label ctitle(`y') keep(SameRace) ///
		bdec(4) sdec(4) rdec(3) adec(3) addstat(Mean, r(mean)) nocons

	}


	***Panel C
	foreach y in Admit ADI lnConsulttime Revisit Death{

		qui xi:reg `y' SameRace i.doctorid $xlist if irelto>2, vce(cluster doctorid)
		
		qui summ `y' if e(sample)
		
		outreg2 using TableA5, excel append label ctitle(`y') keep(SameRace) ///
		bdec(4) sdec(4) rdec(3) adec(3) addstat(Mean, r(mean)) nocons

	}



********************************************************************************
***Table A.6 Robustness: Interactions Between Race and Patient Characteristics
********************************************************************************

	***Panel A

	foreach y in Admit ADI lnConsulttime Revisit Death{

		qui xi:reg `y' SameRace i.doctorid ///
		patracegroup##Male patracegroup##c.age patracegroup##severitylevel ///
		i.consultstarthour i.consultstartdow i.consultstartmonth i.BrDx, vce(cluster doctorid)

		qui summ `y' if e(sample)
		
		outreg2 using TableA6, excel append label ctitle(`y') keep(SameRace) ///
		bdec(4) sdec(4) rdec(3) adec(3) addstat(Mean, r(mean)) nocons


	}


	***Panel B

	foreach y in Admit ADI lnConsulttime Revisit Death {

		qui xi:ivregress 2sls `y' (SameRace=Proportion_Samerace) i.doctorid ///
		patracegroup##Male patracegroup##c.age patracegroup##severitylevel ///
		i.consultstarthour i.consultstartdow i.consultstartmonth i.BrDx, vce(cluster doctorid)

		qui summ `y' if e(sample)
		
		outreg2 using TableA6, excel append label ctitle(`y') keep(SameRace) ///
		bdec(4) sdec(4) rdec(3) adec(3) addstat(Mean, r(mean)) nocons

	}






********************************************************************************
***Table A.7 Heterogeneous Analysis: Patient Severity (IV Estimates)
********************************************************************************

	gen  SameRaceXSeverity= SameRace*severecase

	foreach y in Admit ADI lnConsulttime Revisit Death{

		qui xi: ivregress 2sls `y' (SameRace SameRaceXSeverity =c.Proportion_Samerace##severecase) i.doctorid $xlist, vce(cluster doctorid)
		
		qui summ `y' if e(sample)
		
		outreg2 using TableA7, excel append label ctitle(`y') keep(SameRace  SameRaceXSeverity) ///
		bdec(4) sdec(4) rdec(3) adec(3) addstat(Mean, r(mean)) nocons


	}


********************************************************************************
***Table A.8 Heterogeneous Analysis: Diagnostic Category (IV Estimates)
********************************************************************************

	forvalues i=1(1)4{

	preserve

	keep if SpDx==`i' 

	foreach y in Admit ADI lnConsulttime Revisit Death {

		qui xi: capture noisily ivregress 2sls `y' (SameRace=Proportion_Samerace) i.doctorid $xlist, vce(cluster doctorid)
		
		qui summ `y' if e(sample)
		
		outreg2 using TableA8, excel append label ctitle(`y'_`i') keep(SameRace) ///
		 bdec(4) sdec(4) rdec(3) adec(3) addstat(Mean, r(mean)) nocons
	 
	}

	restore 
	}



********************************************************************************
***Table A.9 Heterogeneous Analysis: Physician Experience (IV Estimates)
********************************************************************************
	
	gen SameRaceXExp=SameRace*experienced

	foreach y in Admit ADI lnConsulttime Revisit Death {

		qui xi:ivregress 2sls `y' (SameRace SameRaceXExp =c.Proportion_Samerace##experienced) experienced i.doctorid $xlist, vce(cluster doctorid)
		
		qui summ `y' if e(sample)
		
		outreg2 using TableA9, excel append label ctitle(`y') keep(SameRace SameRaceXExp experienced) ///
		bdec(4) sdec(4) rdec(3) adec(3) addstat(Mean, r(mean)) nocons

	}



********************************************************************************
***Table A.10 Race Concordance on Diagnosis Granularity (IV Estimate)
********************************************************************************

	foreach y in detailedICD{

		qui xi:ivregress 2sls `y' (SameRace=Proportion_Samerace) i.doctorid $xlist, vce(cluster doctorid)
		
		qui summ `y' if e(sample)
		
		outreg2 using TableA10, excel append label  ctitle(`y') ///
		keep(SameRace) bdec(4) sdec(4) rdec(3) adec(3) addstat(Mean, r(mean)) nocons

	}
